﻿using ConfExpert.Forms.Base;
using DevExpress.XtraEditors.Repository;
using DevTeam;

using System;
namespace ConfExpert.Forms.Depo
{
    public partial class STArtikel : XForm
    {
        public STArtikel()
        {
            InitializeComponent();
        }

        private void STArtikel_Load(object sender, EventArgs e)
        {
            ((RepositoryItemGridLookUpEdit)gleUser.Edit).TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            ((RepositoryItemGridLookUpEdit)gleUser.Edit).Assign(RI(Rp.V_User));
            gleUser.EditValueChanged += gleUser_EditValueChanged;
            gleUser.EditValue = WhoAmI;
          

            gleUser.Enabled = isAdmin; 
            btnKaydet.ItemClick += btnKaydet_ItemClick;
            splitContainerControl1.AutoSize();
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.EndEditing();
            string str = gridView1.SerializeChanges();
            ExecuteNonQuery("UpdSTArtikelSet", str, WhoAmI);
            //gridView1.Update("STArtikelSetId,DegisimTarihi,DegistirenId,YeniProductId,MusteriKullanacakMi", "STArtikelSet");
            Rfrsh();
            gridView1.BestFitColumns();
        }

        void gleUser_EditValueChanged(object sender, EventArgs e)
        {
            Rfrsh();
        }

        void Rfrsh()
        {
            gridView1.Init("GetSTArtikelSet", gleUser.EditValue.ToInt());
            gridView1.AddDetailGrid(gridView2, "RollId");
            gridView1.MakeReadOnly("YeniProductId", "MusteriKullanacakMi");
            gridView2.MakeReadOnly();
            gridView1.MakeColumnInvisible("STArtikelSetId","DegisimTarihi","DegistirenId" ,"Hue"); 
            gridView2.MakeColumnInvisible("Hue");
            gridView1.Columns["YeniProductId"].ColumnEdit = RI(Rp.V_Kumas);

            gridView1.MakeRowSelectable();
            gridView1.FormatAsNumber(1, "Hue");
            gridView2.FormatAsNumber(1, "Hue");
            gridView1.FocusedRowChanged -= gridView1_FocusedRowChanged;
            gridView1.FocusedRowChanged += gridView1_FocusedRowChanged;
            gridView1.BestFitColumns();
            gridView2.BestFitColumns();

            gridView1.AddSummary();
            gridView2.AddSummary();
            gridView1.SetViewCaption("ST kumaşlar");
            gridView2.SetViewCaption("İlgili atölyeye önceki 6 ay içinde gönderilen rengi/deseni yakın kumaşlar");
        }

        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gridView2.BestFitColumns();
        }
    }
}
